home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / AOCE / Development Tools / Sample Code / Standard Catalog Package / DTS AddressOMatic / Src / WindowUtilities.c < prev   
Encoding:
C/C++ Source or Header  |  1993-06-05  |  4.7 KB  |  185 lines  |  [TEXT/KAHL]

  1. /*                                WindowUtilities.c                                */
  2. /*
  3.  * AddressOMatic Sample
  4.  * WindowUtilities.c
  5.  * Copyright © 1993 Apple Computer Inc. All rights reserved.
  6.  */
  7. #include "AddressOMaticTest.h"
  8.  
  9. #ifndef topLeft
  10. #define topLeft(r)    (((Point *) &(r))[0])
  11. #define botRight(r)    (((Point *) &(r))[1])
  12. #endif
  13.  
  14.  
  15. /*
  16.  * DoZoomWindow
  17.  * Algorithm from New Inside Mac (Toolbox Essentials) 4-55
  18.  */
  19. void
  20. DoZoomWindow(
  21.         WindowPtr                theWindow,
  22.         short                    whichPart
  23.     )
  24. {
  25.         GDHandle                gd;
  26.         GDHandle                gdZoom;
  27.         GrafPtr                    savePort;
  28.         Rect                    windowRect;
  29.         Rect                    zoomRect;
  30.         Rect                    intersection;
  31.         long                    thisArea;
  32.         long                    greatestArea;
  33.         short                    windowTitleHeight;
  34. #define PEEK    (*((WindowPeek) theWindow))
  35. #define STATE    (**((WStateDataHandle) PEEK.dataHandle))
  36.  
  37.         GetPort(&savePort);
  38.         SetPort(theWindow);
  39.         if (whichPart == inZoomOut) {
  40.             if (gHasColorQuickDraw == FALSE) {
  41.                 /*
  42.                  * This shouldn't happen on an AOCE system, but,
  43.                  * if it does, just force a single screen zoom.
  44.                  */
  45.                 zoomRect = qd.screenBits.bounds;
  46.                 InsetRect(&zoomRect, 4, 4);
  47.                 STATE.stdState = zoomRect;
  48.             }
  49.             else {
  50.                 /*
  51.                  * We have color QuickDraw. Locate the screen that contains
  52.                  * the largest area of the window and zoom to that screen.
  53.                  */
  54.                 windowRect = theWindow->portRect;
  55.                 LocalToGlobal(&topLeft(windowRect));
  56.                 LocalToGlobal(&botRight(windowRect));
  57.                 windowTitleHeight = windowRect.top
  58.                         - 1
  59.                         - (**PEEK.strucRgn).rgnBBox.top;
  60.                 windowRect.top -= windowTitleHeight;
  61.                 greatestArea = 0;
  62.                 gdZoom = NULL;
  63.                 /*
  64.                  * Look at all graphics devices and find an intersection. Then
  65.                  * select the largest intersecting screen.
  66.                  */
  67.                 for (gd = GetDeviceList(); gd != NULL; gd = GetNextDevice(gd)) {
  68.                     if (TestDeviceAttribute(gd, screenDevice)
  69.                      && TestDeviceAttribute(gd, screenActive)
  70.                      && SectRect(&windowRect, &(**gd).gdRect, &intersection)) {
  71.                         thisArea = ((long) width(intersection))
  72.                                  * ((long) height(intersection));
  73.                         if (thisArea > greatestArea) {
  74.                             greatestArea = thisArea;
  75.                             gdZoom = gd;
  76.                         }
  77.                     }
  78.                 }
  79.                 /*
  80.                  * If we're zooming to the device with the menu bar,
  81.                  * allow for its height.
  82.                  */
  83.                 if (GetMainDevice() == gdZoom)
  84.                     windowTitleHeight += GetMBarHeight();
  85.                 zoomRect = (**gdZoom).gdRect;
  86.                 InsetRect(&zoomRect, 3, 3);
  87.                 zoomRect.top += windowTitleHeight;
  88.                 STATE.stdState = zoomRect;
  89.             }                                        /* End if color QuickDraw    */
  90.         }                                            /* End if zoom out            */
  91.         ZoomWindow(theWindow, whichPart, (theWindow == FrontWindow()));
  92.         /*
  93.          * Zoom redraws the entire window.
  94.          */
  95.         EraseRect(&theWindow->portRect);
  96.         InvalRect(&theWindow->portRect);
  97.         SetPort(savePort);            
  98. #undef PEEK
  99. #undef STATE
  100. }
  101.  
  102. /*
  103.  * DoGrowWindow
  104.  * Algorithm from New Inside Mac (Toolbox Essentials) 4-58
  105.  * We assume that the window can cover the entire screen.
  106.  */
  107. Boolean
  108. DoGrowWindow(
  109.         WindowPtr                theWindow,
  110.         short                    minimumWidth,
  111.         short                    minimumHeight
  112.     )
  113. {
  114.         long                    growSize;
  115.         Rect                    limitRect;
  116.         Rect                    viewRect;
  117.         RgnHandle                localUpdateRgn;
  118.         
  119.         limitRect.left = minimumWidth;
  120.         limitRect.top = minimumHeight;
  121.         limitRect.right = qd.screenBits.bounds.right;
  122.         limitRect.bottom = qd.screenBits.bounds.bottom;
  123.         growSize = GrowWindow(theWindow, EVENT.where, &limitRect);
  124.         if (growSize != 0) {
  125. #if 0    /* This doesn't quite work right    */
  126.             /*
  127.              * Window size changed. Get our update region in
  128.              * local coordinates.
  129.              *
  130.              * viewRect is our "real" content area.
  131.              */
  132.             viewRect = theWindow->portRect;
  133.             localUpdateRgn = NewRgn();
  134.             CopyRgn(((WindowPeek) theWindow)->updateRgn, localUpdateRgn);
  135.             OffsetRgn(
  136.                 localUpdateRgn,
  137.                 theWindow->portBits.bounds.left,
  138.                 theWindow->portBits.bounds.top
  139.             );
  140. #else
  141. #pragma unused (viewRect, localUpdateRgn)
  142. #endif
  143.             SizeWindow(theWindow, LoWord(growSize), HiWord(growSize), TRUE);
  144.             /*
  145.              * Force a redraw of the entire window, but exclude the
  146.              * intersection of the old view rect and the new view rect.
  147.              * Invalidate any prior update region in any case.
  148.              */
  149.             EraseRect(&theWindow->portRect);
  150.             InvalRect(&theWindow->portRect);
  151. #if 0
  152.             (void) SectRect(&viewRect, &theWindow->portRect, &viewRect);
  153.             ValidRect(&viewRect);
  154.             InvalRgn(localUpdateRgn);
  155.             DisposeRgn(localUpdateRgn);
  156. #endif
  157.         }
  158.         return (growSize != 0);
  159. }
  160.  
  161.  
  162. /*
  163.  * Draw the grow box, but don't draw the scroll bar lines.
  164.  */
  165. void
  166. MyDrawGrowIcon(
  167.         WindowPtr            theWindow
  168.     )
  169. {
  170.         RgnHandle            clipRgn;
  171.         Rect                clipRect;
  172.         
  173.         clipRgn = NewRgn();
  174.         GetClip(clipRgn);
  175.         clipRect = theWindow->portRect;
  176.         clipRect.top = clipRect.bottom - (kScrollBarWidth - 1);
  177.         clipRect.left = clipRect.right - (kScrollBarWidth - 1);
  178.         ClipRect(&clipRect);
  179.         DrawGrowIcon(theWindow);
  180.         ValidRect(&clipRect);
  181.         SetClip(clipRgn);
  182.         DisposeRgn(clipRgn);
  183. }
  184.  
  185.